package com.moji.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.moji.common.entity.MyPage;
import com.moji.common.utils.PageUtil;
import com.moji.entity.MjOpinion;
import com.moji.entity.MjSeo;
import com.moji.entity.dto.QueryOpinionDto;
import com.moji.entity.dto.QuerySeoDto;
import com.moji.mapper.MjSeoMapper;
import com.moji.service.MjSeoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moji.util.IdGenerator;
import com.moji.util.MoJiCommonUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ccl
 * @since 2024-08-15
 */
@Service
public class MjSeoServiceImpl extends ServiceImpl<MjSeoMapper, MjSeo> implements MjSeoService {

    @Resource
    private IdGenerator idGenerator;

    @Override
    public MyPage<MjSeo> queryByPage(QuerySeoDto dto) {
        LambdaQueryWrapper<MjSeo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ObjectUtil.isNotEmpty(dto.getType()),MjSeo::getType,dto.getType());
        wrapper.eq(ObjectUtil.isNotEmpty(dto.getType()),MjSeo::getType,dto.getType());
        wrapper.eq(ObjectUtil.isNotEmpty(dto.getTitle()),MjSeo::getType,dto.getTitle());
        wrapper.eq(ObjectUtil.isNotEmpty(dto.getKeywords()),MjSeo::getType,dto.getKeywords());
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        List<MjSeo> mjSeoList = list(wrapper);
        PageInfo<MjSeo> info = new PageInfo<>(mjSeoList);
        return PageUtil.PageInfo2MyPage(info);
    }

    @Override
    public boolean delete(Long id) {
        if(ObjectUtil.isEmpty(id)){
            throw new RuntimeException("主键ID不能为空,请核查!");
        }
        return this.removeById(id);
    }

    @Override
    public boolean add(MjSeo mjSeo) {
        return this.save(mjSeo);
    }

    @Override
    public boolean edit(MjSeo mjSeo) {
        MjSeo mjSeo1=this.getById(mjSeo.getId());
        BeanUtils.copyProperties(mjSeo,mjSeo1);
        return this.updateById(mjSeo1);
    }

    @Override
    public MjSeo detail(Long id) {
        if(ObjectUtil.isEmpty(id)){
            throw new RuntimeException("主键ID不能为空,请核查!");
        }
        MjSeo mjSeo=this.getById(id);
        return mjSeo;
    }
}
